let uu = document.querySelector('ul')
let foot = document.querySelector('.footer1>div>b:nth-of-type(3)')
let span = document.querySelector('span')

fetch('http://chst.vip:1234/api/getcategorytitle')
    .then(body => body.json())
    .then(res => {
        render(res.result, uu)
    })
function render(data, el) {
    let domStr = ''
    data.forEach(item => {
        domStr += `<li titleid=${item.titleId}>${item.title}
        <div class="categorys"></div>
        </li>`
        el.innerHTML = domStr
    })
}

uu.onclick = function (e) {
    if (e.target.localName === 'li') {
        let _this = e.target
        let titleid = _this.getAttribute('titleid')
        titleid = Number(titleid)
        fetch("http://chst.vip:1234/api/getcategory?titleid=" + titleid)
            .then(body => body.json())
            .then(res => {
                let listArr = res.result
                let listStr = ''
                listArr.forEach(item => {
                    listStr += `<div><p categoryid=${item.categoryId}>${item.category}</p></div>`
                    $(_this).find('.categorys').html(listStr)
                })
            })
    } else if (e.target.localName == 'p') {
        if (e.target.localName == 'p') {
            let _this = e.target
            console.log(_this)
            let id = _this.getAttribute('categoryid')
            console.log(id);
            location.href = "../html/bijiayemian.html?categoryid=" + id
            id = Number(id)
            console.log(id)

        }
    }

}





span.onclick = function () {
    location.href = "./../index.html"
}
foot.onclick = function () {
    location.href = "./../index.html"
}

$('.uu').find('.categorys').slideUp(0, function () {
    $('.categorys').css('display', 'none')
    $('.categorys').prop('flag', false)
})
$('.uu').on('click', 'li', function () {
    console.log(this)
    let flag = $(this).find('.categorys').prop('flag')
    if (flag) {
        $(this).find('.categorys').slideUp(500).prop('flag', false)
        return
    }
    $(this).find('.categorys').slideDown(500).prop('flag', true).parent().siblings().find('.categorys').slideUp(500).prop('flag', false)
})